#include "TCurve.h"


//-------------------------------------

TCurve::TCurve( QString name ) :
    QwtPlotCurve( name ),
    useSpline( true )
{
    fitter = new QwtSplineCurveFitter();
    this->setCurveFitter( fitter );
    this->setStyle( QwtPlotCurve::Lines );
    this->setCurveAttribute( QwtPlotCurve::Fitted );
    //fitter->spline().setSplineType( QwtSpline::Periodic );

    dot = new QwtSymbol();
    SetDotStyle();
    SetDotColor();
    SetDotSize();
    setSymbol( dot );
}

//-------------------------------------
/*
TCurve::~TCurve()
{
    delete fitter;
    delete dot;
}
*/
//-------------------------------------

void TCurve::SetSplineSize( int n )
{
    if( n > points.count()-1 )
        fitter->setSplineSize( n );
    else
        fitter->setSplineSize( points.count()-1 );
    setSamples( points );
}

//-------------------------------------

void TCurve::SetSamples( const QVector< QPointF > & p )
{
    points = p;
    setSamples( points );
    fitter->spline().setPoints( points );
    SetSplineSize( points.count()-1 );
}

//-------------------------------------

double TCurve::GetY( double x )
{
    //if( fitter->spline().points().count() )
        return fitter->spline().value( x );
    //return 0;
}

//-------------------------------------

void TCurve::SetDotColor( QColor c )
{
    dot->setPen( QPen( c ) );
    QBrush b = dot->brush();
    b.setColor( c );
    dot->setBrush( b );
}

//-------------------------------------

void TCurve::UseSpline( bool s )
{
    useSpline = s;
    if( useSpline )
        setCurveAttribute( QwtPlotCurve::Fitted );
    else
        setCurveAttribute( QwtPlotCurve::Fitted, false );
}

//-------------------------------------





